package pl.us.ij.plugins.segmentation.commands.watershed;

import ij.ImagePlus;
import ij.process.FloatProcessor;
import pl.us.ij.plugins.segmentation.infrastructure.exceptions.BreakCommandException;

/**
 * Created by IntelliJ IDEA.
 * User: Przemek
 * Date: 2010-01-07
 * Time: 15:29:39
 * To change this template use File | Settings | File Templates.
 */
public class CombineSegmentationCommand extends WatershedSegmentationCommand {

    @Override
    protected void processImage(FloatProcessor fp) throws BreakCommandException {
        int width = fp.getWidth();
        int height = fp.getHeight();

        fp.snapshot();

        super.processImage(fp);

        float[] copyPixels = (float[]) fp.getPixelsCopy();

        fp.reset();

        float[] pixels = (float[]) fp.getPixels();

        for (int y = 0; y < height; y++) {
            int shiftD = y * width;

            for (int x = 0; x < width; x++) {
                if (copyPixels[shiftD + x] == 255) {
                    pixels[shiftD + x] = 255;
                }
            }
        }
    }

    @Override
    protected ImagePlus prepareOutImage(ImagePlus inImage) {
        
        return super.prepareOutImage(inImage);    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected boolean finalizeOutImage(ImagePlus outImp) {
        return true;
    }
}
